package com.manli.api.controller;

import java.util.Arrays;
import java.util.Map;

import com.manli.api.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.dto.GoodsDef;
import com.manli.api.service.GoodsDefService;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author manli
 * @email 
 * @date 2020-05-12 09:11:18
 */
@Api(value="/goodsdef", tags="商品定义")
@RestController
@RequestMapping("api/goodsdef")
public class GoodsDefController {
    @Autowired
    private GoodsDefService goodsDefService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表",notes = "")
    @PostMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result list(@RequestBody QueryParamsGoodsDefs params){
        return goodsDefService.queryPage1(params);
    }

    /**
     * 获取店面下商品分类
     */
    @ApiOperation(value = "获取店面下商品分类",notes = "")
    @PostMapping("/getGoodsTypeInStore")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result getGoodsTypeInStore(HttpServletRequest request){
        return goodsDefService.getGoodsTypeInStore(request);
    }

    /**
     * 审核列表
     */
    @ApiOperation(value = "审核列表",notes = "")
    @PostMapping("/verifyList")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result verifyList(@RequestBody QueryParamsGoodsDefsVer params){
        return goodsDefService.queryPage2(params);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "全部数据信息",notes = "")
    @PostMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result all(@RequestBody QueryParamsGoodsDefs params){
        return goodsDefService.queryAll(params);
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "单条信息",notes = "单条信息")
    @GetMapping("/info/{goodsDefId}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result info(@PathVariable("goodsDefId") Integer goodsDefId){
        return goodsDefService.getById(goodsDefId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存",notes = "保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result save(@RequestBody GoodsDef goodsDef,HttpServletRequest request){
        return goodsDefService.save(goodsDef,request);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改",notes = "修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result update(@RequestBody GoodsDef goodsDef,HttpServletRequest request){
        return goodsDefService.updateById(goodsDef,request);
    }

    /**
     * 修改状态专用
     */
    @ApiOperation(value = "修改状态专用",notes = "修改状态专用")
    @PostMapping("/updateStatusById")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result updateStatusById(@RequestBody GoodsDef goodsDef,HttpServletRequest request){
        return goodsDefService.updateStatusById(goodsDef,request);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "goodsDefIds", value = "id",dataType = "int", required = true)
    @PostMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result delete(@RequestBody QueryParamsGoodsDefDel goodsDefId){
        return goodsDefService.removeById(goodsDefId);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "goodsDefIds", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @PostMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result deleteIds(@RequestBody Integer[] goodsDefIds){
        return goodsDefService.removeByIds(Arrays.asList(goodsDefIds));
    }

}
